package com.nyist.diseasepreventionserver.model.pager;

import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

/**
 * @Auther: 杜習田
 * @Date: 2020/2/29 15:39
 * @Description:
 */
@Service
public class PagerServiceImpl implements PagerService{

    @Override
    public Pageable defPager(int pageNum, int pageSize) {
        return PageRequest.of(pageNum-1,pageSize);
    }

    @Override
    public Pageable sortASCPager(String sortString, int pageNum, int pageSize) {
        Sort sort = Sort.by(Sort.Direction.ASC,sortString);
        return PageRequest.of(pageNum-1,pageSize,sort);
    }

    @Override
    public Pageable sortDescPager(String sortString, int pageNum, int pageSize) {
        Sort sort = Sort.by(Sort.Direction.DESC,sortString);
        return PageRequest.of(pageNum-1,pageSize,sort);
    }
}
